home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / BSPASSWD.C < prev    next >
C/C++ Source or Header  |  1993-05-20  |  4KB  |  113 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    bspasswd.c
  5. //   Title:    Base Library
  6. //  Notice:    Copyright (c) 1991-1993, John Weeder, All Rights Reserved.
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains code to handle passwords. Passwords are always stored
  25. //    externally as 4 byte key values. Internally a password consists of two
  26. //    ASCII zero terminated strings which are combined form the key. Passwords
  27. //    are verified by re-submitting the strings ands key. Normally the two 
  28. //    strings are a password and user id.
  29. //
  30. //    The code in this module should be written entirely in C. 
  31. //    Do not use any C++ constructs.
  32. //
  33. //    This module is portable to:
  34. //        DOS 3.X+
  35. //        MS Windows 3.X+
  36. //        OS/2 2.X+
  37. //        OS/2 2.0 PM
  38. //        SCO UNIX.
  39. //
  40. //    The following compilers are supported:
  41. //        MSC 6.0A
  42. //        MSC/C++ 7.0
  43. //        Borland C++ 3.1 for DOS
  44. //        Borland C++ 1.0 for OS/2 2.X
  45. //        SCO UNIX cc
  46. //
  47. //----------------------------------------------------------------------------
  48. #include <bs.h>
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //   Description:    Get password key.
  53. //                          NOTE: Order of password strings is significant!!
  54. //    Parameters:    pcsz1, pcsz2        Two strings to generate passowrd from.
  55. //       Returns:    Key
  56. //----------------------------------------------------------------------------
  57. ULONG FN_E PasswordGet(PCSZ pcsz1, PCSZ pcsz2)
  58. {
  59.     CRC crc = CrcCalc((PBYTE)pcsz1, strlen(pcsz1) + 1);
  60.     crc = CrcCalcAppend((PBYTE)pcsz2, strlen(pcsz2) + 1, crc);
  61.     return (ULONG)crc;
  62. }
  63.  
  64.  
  65. //----------------------------------------------------------------------------
  66. //   Description:    Verify password key.
  67. //                          NOTE: Order of password strings is significant!!
  68. //    Parameters:    pcsz1, pcsz2        Two strings to generate passowrd from.
  69. //       Returns:    TRUE if password is verified
  70. //----------------------------------------------------------------------------
  71. BOOL FN_E PasswordVerify(PCSZ pcsz1, PCSZ pcsz2, ULONG ulKey)
  72. {
  73.     ULONG ulKey2 = PasswordGet(pcsz1, pcsz2);
  74.     return ulKey == ulKey2;
  75. }
  76.  
  77.  
  78. //----------------------------------------------------------------------------
  79. //   Description:    Run standard test suite
  80. //    Parameters:    sTest        Test to run.
  81. //                                        0        Run all default tests (except).
  82. //       Returns:    TRUE if successful.
  83. //----------------------------------------------------------------------------
  84. #if COMPILE_TEST
  85. BOOL FN PasswordTest(SHORT sTest)
  86. {
  87. static PCSZ pcsz1 = "John Marvin Weeder";
  88. static PCSZ pcsz2 = "Carol Sue Weeder";
  89. static PCSZ pcsz3 = "John Marvin Weedes";
  90.  
  91.     ULONG ulKey = PasswordGet(pcsz1, pcsz2);
  92.  
  93.  
  94.     NOTUSED(sTest);
  95.     Output("  1: %s\n  2: %s\nKey: %08lX\n",
  96.         pcsz1, pcsz2, ulKey);
  97.     
  98.     if (!PasswordVerify(pcsz1, pcsz2, ulKey))
  99.         return FALSE;
  100.  
  101.     if (PasswordVerify(pcsz2, pcsz1, ulKey))
  102.         return FALSE;
  103.  
  104.     if (PasswordVerify(pcsz1, pcsz3, ulKey))
  105.         return FALSE;
  106.  
  107.     return TRUE;
  108. }
  109. #endif
  110. //----------------------------------------------------------------------------
  111. //------------------------------- End of File --------------------------------
  112. //----------------------------------------------------------------------------
  113.